{% extends "base.html" %}
{% block content %}
<script type="text/javascript" src="/static/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/static/js/jquery.cookie.min.js"></script>
<script type="text/javascript" src="/static/js/artDialog/jquery.artDialog.js?skin=default"></script>
<script type="text/javascript" src="/static/js/artDialog/plugins/iframeTools.js"></script>
{{ttt}}
{% ifequal is_con 0 %}
<table width="100%">
		<tr style="background:#dfdfdf;">
			<td align="center"><h1  style="line-height:40px;font-size:18px;color:#10D3F8">Sent Mail List</h1></td>
		</tr>
</table>
<div class="form-div">
  <form action="" method="get" name="searchForm">
    <img src="/static/images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH" />
	ListName:
		<input type='text' name='listname' value='{% if listname %}{{listname}}{%endif%}'/>
	AddUser:
		<input type='text' name='adduser' value='{% if adduser %}{{adduser}}{%endif%}'/>
	<input type="button" value="Search" id='search' class="g-button g-button-submit"/>
  </form>
</div>
<script>
$(function(){
	$("#search").bind({
		click:function(){
			var t = this
			if(t.style.cursor == 'wait'){
				return false;
			}
			t.style.cursor = 'wait'
			var data = $('form[name="searchForm"]').serializeArray()
			var datas = {'is_con':1}
			for(var i=0;i<data.length;i++){
				datas[data[i].name] = data[i].value
			}
			$.ajax({
				url:'',
				data:datas,
				type:'get',
				dataType:'html',
				success:function(e){
					t.style.cursor = 'pointer'
					$('#return').html(e)
				}
			})
		}
	})
});
</script>
	<style>
		.emaillist{
			float:left;
			padding:3px;
			margin:2px;
			border:1px solid #def;
		}
		.emaillist:hover{
			background:#efefef;
			cursor:pointer;
		}
	</style>
{% endifequal %}
<div id="return">
	<table width="100%" align="center" cellpadding="1" class="aui-ibox-data aui-dotted-split">
	  <thead>
		<tr>
			<th align="left" width="190">MailList</th>
			<th align="left" width="150">MailSubject</th>
			<th align="left" width="100">MailInfo</th>
			<th align="left" width="120">SendTime</th>
			<th align="left" width="80">SendUser</th>
			<th align="left" width="120">SendState</th>
			<th align="left" width="80">Opened</th>
			<th align="left" width="80">Bounced</th>
			<th align="left" width="">Bounced</th>
		</tr>
	  </thead>
	  <tbody>
	  {% if mails %}
		{%for m in mails %}
		<tr>
			<td align="left"><a href="/{{m.11}}" class="filepath">{{m.12}}({{m.1}})</a></td>
			<td align="left">{{m.5}}</td>
			<td align="left">
				<span style="color:blue;cursor:pointer;" class="show_maillist" lid='{{m.0}}'>Particulars</span>
			</td>
			<td align="left">{{m.8}}</td>
			<td align="left">{{m.9}}</td>
			<td align="left">
				{%ifequal m.6 0%}<font color='green'>Mail Error</font>{%endifequal%}
				{%ifequal m.6 1%}<font color='green'>Mail Success</font>{%endifequal%}
				{%ifequal m.6 2%}<font color='gray'>Mail Fail&nbsp;[<span class="resend" letid="{{m.4}}" logid="{{m.0}}" maillistid="{{m.1}}" obj="{{m.5}}" newletterid="{{m.3}}" style="color:red;cursor:pointer;">Resend</span>]</font>{%endifequal%}
			</td>
			<td></td>
			<td></td>
			<td></td>
		</tr>
		{% endfor %}
	  {%else%}
	    <tr>
			<td align="center" valign="center" height="60" colspan="10" style="color:green;font-size:16px;line-height: 60px;">No Results !</td>
		</tr>
	  {%endif%}
		<tr>
			<td align="center" colspan="10">
				<div id="pages" class="pager"></div>
			</td>
		</tr>
	  </tbody>
	</table>
</div>
<script>
(function(){
	$('span.show_maillist').click(function(){
		var lid = $(this).attr('lid')
		var dialog = art.dialog({title:'Mail Particulars',lock:true})
		$.get('/gmailinfo/',{'mlid':lid},function(e){
			dialog.content(e)
			dialog.button({name:'close'})
		})
	})
	$('span.resend').click(function(){
		var letid = $(this).attr('letid')
		var logid = $(this).attr('logid')
		var maillistid = $(this).attr('maillistid')
		var newletterid = $(this).attr('newletterid')
		var object = $(this).attr('obj')
		var data = {'letid':letid,'logid':logid,'maillistid':maillistid,'newletterid':newletterid,'object':object,'host':location.host}
		var dialog = art.dialog({title:'Mail Send...',lock:true})
		$.post('/gsendmail/',data,function(e,code){
			if(code == 'success'){
				var user = JSON.parse(e);
				if(user['code']==1){
					dialog.title('Successful!')
					dialog.content(user['info']);
					dialog.button({name:'OK',callback:(function(){window.location.reload();})})
				}else{
					dialog.title('ERROR!')
					dialog.content(user['info']);
					dialog.button({name:'close'})
				}
			}
		})
	})
	$('a.filepath').click(function(){
		var url = $(this).attr('href')
		var dialog = art.dialog({'id':'N1006','title':'EmailInfo',ok:true,width:400})
		$.get(url,function(e){
			var data = e.split('\r\n')
			var html = ''
			for(var i=0;i<data.length;i++){
				if(data[i]=='')continue;
				html += '<div class="emaillist">'+data[i]+'</div>'
			}
			if (html==''){
				html = 'This E-mail list is empty!'
			}
			dialog.content(html)
		})
		return false;
	})
	function initdata(){
		var tolpage = {{tolpage}}
		if(tolpage<=1)return false;
		for(var i=1;i<=tolpage;i++){
			var c = ''
			if(i=={{page}}){
				c = 'active'
			}
			$('#pages').append("<li><a href='?is_con=1&listname={% if listname %}{{listname}}{%endif%}&adduser={% if adduser %}{{adduser}}{%endif%}&page="+i+"' onclick=\"$.get(this.href,function(e){$(\'#return\').html(e)});return false;\" class='"+c+"'>"+i+"</a></li>")
		}
	}
	initdata()
})()
</script>
{% endblock %}
